package com.njlime.cms.service.app;

import com.njlime.cms.entities.LiveUp;
import com.njlime.cms.repository.app.AppLiveUpDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by Dean on 2017/10/10.
 */
@Service
public class AppLiveUpService {
    @Resource
    AppLiveUpDao appLiveUpDao;
    @Resource
    AppLiveCommentService appLiveCommentService;

    /**
     * 判断当前live评论是否被点赞
     */
    public Boolean isUped(Integer commentId, Integer userId) {
        int upCount = appLiveUpDao.userUpCount(commentId, userId);
        if (upCount > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 点赞
     */
    @Transactional(readOnly = false)
    public void save(LiveUp liveUp) {
        appLiveUpDao.save(liveUp);
        appLiveCommentService.fabulousNumUpdate(liveUp.getComment_id(), 1);
    }

    /**
     * 取消点赞
     */
    @Transactional(readOnly = false)
    public void del(Integer commentId, Integer userId) {
        appLiveUpDao.del(commentId, userId);
        appLiveCommentService.fabulousNumUpdate(commentId, -1);
    }
}

